package zhaomh.zhlib.config;

import zhaomh.zhlib.util.TextUtil;

import java.util.ArrayList;
import java.util.List;

public class Value {
    private final String name;
    private final List<ValueListener> listeners = new ArrayList<>();
    public Value(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public String getTrName() {
        return TextUtil.Translatable(name).getString();

    }

    public String getDescription() {
        return TextUtil.Translatable(name+".description").getString();
    }


    public void addListener(ValueListener listener) {
        if (!listeners.contains(listener)) {
            listeners.add(listener);
        }
    }

    public void removeListener(ValueListener listener) {
        listeners.remove(listener);
    }

    protected void notifyListeners() {
        for (ValueListener listener : listeners) {
            listener.onValueChanged(this);
        }
    }

    @Override
    public boolean equals(Object obj) {
        return obj instanceof Value value && value.getName().equals(name);
    }
}
